﻿// =================================================================== 
// 项目说明
//====================================================================
// Wup。@Copy Right 2014
// 文件： UserViewHistory.cs
// 项目名称：买车网
// 创建时间：2016/3/23
// 负责人：Wup
// ===================================================================
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using Weixin.Entity.ChinaTax;
using Weixin.Utils;


namespace Weixin.DAL.ChinaTax
{
    /// <summary>
    /// 数据层实例化接口类 dbo.UserViewHistory.
    /// </summary>
    public partial class UserViewHistoryDataAccessLayer 
    {
		#region 构造函数


		/// <summary>
		/// 
		/// </summary>
		public UserViewHistoryDataAccessLayer()
		{
		}
		#endregion

        #region -----------实例化接口函数-----------
		
		#region 添加更新删除
		/// <summary>
		/// 向数据库中插入一条新记录。
		/// </summary>
		/// <param name="_UserViewHistoryModel">UserViewHistory实体</param>
		/// <returns>新插入记录的编号</returns>
		public int Insert(UserViewHistoryEntity _UserViewHistoryModel)
		{
			string sqlStr="insert into UserViewHistory([UserId],[ObjId],[ObjType],[CreateTime],[IP],[SourceId],[OperateWay]) values(@UserId,@ObjId,@ObjType,@CreateTime,@IP,@SourceId,@OperateWay) select @@identity";
			int res;
			SqlParameter[] _param={
			new SqlParameter("@UserId",SqlDbType.Int),
			new SqlParameter("@ObjId",SqlDbType.Int),
			new SqlParameter("@ObjType",SqlDbType.Int),
			new SqlParameter("@CreateTime",SqlDbType.DateTime),
			new SqlParameter("@IP",SqlDbType.VarChar),
			new SqlParameter("@SourceId",SqlDbType.Int),
			new SqlParameter("@OperateWay",SqlDbType.Int)
			};			
			_param[0].Value=_UserViewHistoryModel.UserId;
			_param[1].Value=_UserViewHistoryModel.ObjId;
			_param[2].Value=_UserViewHistoryModel.ObjType;
			_param[3].Value=_UserViewHistoryModel.CreateTime;
			_param[4].Value=_UserViewHistoryModel.IP;
			_param[5].Value=_UserViewHistoryModel.SourceId;
			_param[6].Value=_UserViewHistoryModel.OperateWay;
			res = Convert.ToInt32(SqlHelper.ExecuteScalar(WebConfig.ChinaTax,CommandType.Text,sqlStr,_param));
			return res;
		}
		/// <summary>
		/// 向数据库中插入一条新记录。带事务
		/// </summary>
		/// <param name="sp">事务对象</param>
		/// <param name="_UserViewHistoryModel">UserViewHistory实体</param>
		/// <returns>新插入记录的编号</returns>
		public int Insert(SqlTransaction sp,UserViewHistoryEntity _UserViewHistoryModel)
		{
			string sqlStr="insert into UserViewHistory([UserId],[ObjId],[ObjType],[CreateTime],[IP],[SourceId],[OperateWay]) values(@UserId,@ObjId,@ObjType,@CreateTime,@IP,@SourceId,@OperateWay) select @@identity";
			int res;
			SqlParameter[] _param={
			new SqlParameter("@UserId",SqlDbType.Int),
			new SqlParameter("@ObjId",SqlDbType.Int),
			new SqlParameter("@ObjType",SqlDbType.Int),
			new SqlParameter("@CreateTime",SqlDbType.DateTime),
			new SqlParameter("@IP",SqlDbType.VarChar),
			new SqlParameter("@SourceId",SqlDbType.Int),
			new SqlParameter("@OperateWay",SqlDbType.Int)
			};			
			_param[0].Value=_UserViewHistoryModel.UserId;
			_param[1].Value=_UserViewHistoryModel.ObjId;
			_param[2].Value=_UserViewHistoryModel.ObjType;
			_param[3].Value=_UserViewHistoryModel.CreateTime;
			_param[4].Value=_UserViewHistoryModel.IP;
			_param[5].Value=_UserViewHistoryModel.SourceId;
			_param[6].Value=_UserViewHistoryModel.OperateWay;
			res = Convert.ToInt32(SqlHelper.ExecuteScalar(sp,CommandType.Text,sqlStr,_param));
			return res;
		}


		/// <summary>
		/// 向数据表UserViewHistory更新一条记录。
		/// </summary>
		/// <param name="_UserViewHistoryModel">_UserViewHistoryModel</param>
		/// <returns>影响的行数</returns>
		public int Update(UserViewHistoryEntity _UserViewHistoryModel)
		{
            string sqlStr="update UserViewHistory set [UserId]=@UserId,[ObjId]=@ObjId,[ObjType]=@ObjType,[CreateTime]=@CreateTime,[IP]=@IP,[SourceId]=@SourceId,[OperateWay]=@OperateWay where Id=@Id";
			SqlParameter[] _param={				
				new SqlParameter("@Id",SqlDbType.Int),
				new SqlParameter("@UserId",SqlDbType.Int),
				new SqlParameter("@ObjId",SqlDbType.Int),
				new SqlParameter("@ObjType",SqlDbType.Int),
				new SqlParameter("@CreateTime",SqlDbType.DateTime),
				new SqlParameter("@IP",SqlDbType.VarChar),
				new SqlParameter("@SourceId",SqlDbType.Int),
				new SqlParameter("@OperateWay",SqlDbType.Int)
				};				
				_param[0].Value=_UserViewHistoryModel.Id;
				_param[1].Value=_UserViewHistoryModel.UserId;
				_param[2].Value=_UserViewHistoryModel.ObjId;
				_param[3].Value=_UserViewHistoryModel.ObjType;
				_param[4].Value=_UserViewHistoryModel.CreateTime;
				_param[5].Value=_UserViewHistoryModel.IP;
				_param[6].Value=_UserViewHistoryModel.SourceId;
				_param[7].Value=_UserViewHistoryModel.OperateWay;
			return SqlHelper.ExecuteNonQuery(WebConfig.ChinaTax,CommandType.Text,sqlStr,_param);
		}
		/// <summary>
		/// 向数据表UserViewHistory更新一条记录。带事务
		/// </summary>
		/// <param name="sp">事务对象</param>
		/// <param name="_UserViewHistoryModel">_UserViewHistoryModel</param>
		/// <returns>影响的行数</returns>
		public int Update(SqlTransaction sp,UserViewHistoryEntity _UserViewHistoryModel)
		{
            string sqlStr="update UserViewHistory set [UserId]=@UserId,[ObjId]=@ObjId,[ObjType]=@ObjType,[CreateTime]=@CreateTime,[IP]=@IP,[SourceId]=@SourceId,[OperateWay]=@OperateWay where Id=@Id";
			SqlParameter[] _param={				
				new SqlParameter("@Id",SqlDbType.Int),
				new SqlParameter("@UserId",SqlDbType.Int),
				new SqlParameter("@ObjId",SqlDbType.Int),
				new SqlParameter("@ObjType",SqlDbType.Int),
				new SqlParameter("@CreateTime",SqlDbType.DateTime),
				new SqlParameter("@IP",SqlDbType.VarChar),
				new SqlParameter("@SourceId",SqlDbType.Int),
				new SqlParameter("@OperateWay",SqlDbType.Int)
				};				
				_param[0].Value=_UserViewHistoryModel.Id;
				_param[1].Value=_UserViewHistoryModel.UserId;
				_param[2].Value=_UserViewHistoryModel.ObjId;
				_param[3].Value=_UserViewHistoryModel.ObjType;
				_param[4].Value=_UserViewHistoryModel.CreateTime;
				_param[5].Value=_UserViewHistoryModel.IP;
				_param[6].Value=_UserViewHistoryModel.SourceId;
				_param[7].Value=_UserViewHistoryModel.OperateWay;
			return SqlHelper.ExecuteNonQuery(sp,CommandType.Text,sqlStr,_param);
		}		
		
		
		/// <summary>
		/// 删除数据表UserViewHistory中的一条记录
		/// </summary>
	    /// <param name="Id">id</param>
		/// <returns>影响的行数</returns>
		public int Delete(int Id)
		{
			string sqlStr="delete from UserViewHistory where [Id]=@Id";
			SqlParameter[] _param={			
			new SqlParameter("@Id",SqlDbType.Int),
			
			};			
			_param[0].Value=Id;
			return SqlHelper.ExecuteNonQuery(WebConfig.ChinaTax,CommandType.Text,sqlStr,_param);
		}
		
		/// <summary>
		/// 删除数据表UserViewHistory中的一条记录,带事务
		/// </summary>
		/// <param name="sp">事务对象</param>
	    /// <param name="Id">id</param>
		/// <returns>影响的行数</returns>
		public int Delete(SqlTransaction sp,int Id)
		{
			string sqlStr="delete from UserViewHistory where [Id]=@Id";
			SqlParameter[] _param={			
			new SqlParameter("@Id",SqlDbType.Int),
			
			};			
			_param[0].Value=Id;
			return SqlHelper.ExecuteNonQuery(sp,CommandType.Text,sqlStr,_param);
		}
		#endregion
		
		#region 数据实体
		/// <summary>
		/// 得到  userviewhistory 数据实体
		/// </summary>
		/// <param name="row">row</param>
		/// <returns>userviewhistory 数据实体</returns>
		public UserViewHistoryEntity Populate_UserViewHistoryEntity_FromDr(DataRow row)
		{
			UserViewHistoryEntity Obj = new UserViewHistoryEntity();
			if(row!=null)
			{
				Obj.Id = (( row["Id"])==DBNull.Value)?0:Convert.ToInt32( row["Id"]);
				Obj.UserId = (( row["UserId"])==DBNull.Value)?0:Convert.ToInt32( row["UserId"]);
				Obj.ObjId = (( row["ObjId"])==DBNull.Value)?0:Convert.ToInt32( row["ObjId"]);
				Obj.ObjType = (( row["ObjType"])==DBNull.Value)?0:Convert.ToInt32( row["ObjType"]);
				Obj.CreateTime = (( row["CreateTime"])==DBNull.Value)?Convert.ToDateTime("1900-1-1"):Convert.ToDateTime( row["CreateTime"]);
				Obj.IP =  row["IP"].ToString();
				Obj.SourceId = (( row["SourceId"])==DBNull.Value)?0:Convert.ToInt32( row["SourceId"]);
				Obj.OperateWay = (( row["OperateWay"])==DBNull.Value)?0:Convert.ToInt32( row["OperateWay"]);
			}
			else
			{
				return null;
			}
			return Obj;
		}
		
        /// <summary>
		/// 得到  userviewhistory 数据实体
		/// </summary>
		/// <param name="dr">dr</param>
		/// <returns>userviewhistory 数据实体</returns>
		public UserViewHistoryEntity Populate_UserViewHistoryEntity_FromDr(IDataReader dr)
		{
			UserViewHistoryEntity Obj = new UserViewHistoryEntity();
			
				Obj.Id = (( dr["Id"])==DBNull.Value)?0:Convert.ToInt32( dr["Id"]);
				Obj.UserId = (( dr["UserId"])==DBNull.Value)?0:Convert.ToInt32( dr["UserId"]);
				Obj.ObjId = (( dr["ObjId"])==DBNull.Value)?0:Convert.ToInt32( dr["ObjId"]);
				Obj.ObjType = (( dr["ObjType"])==DBNull.Value)?0:Convert.ToInt32( dr["ObjType"]);
				Obj.CreateTime = (( dr["CreateTime"])==DBNull.Value)?Convert.ToDateTime("1900-1-1"):Convert.ToDateTime( dr["CreateTime"]);
				Obj.IP =  dr["IP"].ToString();
				Obj.SourceId = (( dr["SourceId"])==DBNull.Value)?0:Convert.ToInt32( dr["SourceId"]);
				Obj.OperateWay = (( dr["OperateWay"])==DBNull.Value)?0:Convert.ToInt32( dr["OperateWay"]);
			
			return Obj;
		}
		#endregion
		
		/// <summary>
		/// 根据ID,返回一个UserViewHistory对象
		/// </summary>
		/// <param name="id">id</param>
		/// <returns>UserViewHistory对象</returns>
		public UserViewHistoryEntity Get_UserViewHistoryEntity (int id)
		{
			UserViewHistoryEntity _obj=null;
			SqlParameter[] _param={
			new SqlParameter("@Id",SqlDbType.Int)
			};
			_param[0].Value=id;
			string sqlStr="select * from UserViewHistory with(nolock) where Id=@Id";
			using(SqlDataReader dr=SqlHelper.ExecuteReader(WebConfig.ChinaTax,CommandType.Text,sqlStr,_param))
			{
				while(dr.Read())
				{
            		_obj=Populate_UserViewHistoryEntity_FromDr(dr);
				}
			}
			return _obj;
		}
		/// <summary>
		/// 得到数据表UserViewHistory所有记录
		/// </summary>
		/// <returns>数据集</returns>
		public IList< UserViewHistoryEntity> Get_UserViewHistoryAll()
		{
			IList< UserViewHistoryEntity> Obj=new List< UserViewHistoryEntity>();
			string sqlStr="select * from UserViewHistory";
			using(SqlDataReader dr=SqlHelper.ExecuteReader(WebConfig.ChinaTax,CommandType.Text,sqlStr))
			{
				while(dr.Read())
				{
					Obj.Add(Populate_UserViewHistoryEntity_FromDr(dr));
				}
			}
			return Obj;
		}
		/// <summary>
        /// 检测是否存在根据主键
        /// </summary>
        /// <param name="id">id</param>
        /// <returns>是/否</returns>
		public bool IsExistUserViewHistory(int id)
		{
			SqlParameter[] _param={
                                      new SqlParameter("@id",SqlDbType.Int)
                                  };
            _param[0].Value=id;
            string sqlStr="select Count(*) from UserViewHistory where Id=@id";
            int a=Convert.ToInt32(SqlHelper.ExecuteScalar(WebConfig.ChinaTax,CommandType.Text,sqlStr,_param));
            if(a>0)
            {
                return true;
            }
            else
            {
                return false;
            }
		}

        #endregion
		
		#region----------自定义实例化接口函数----------
		#endregion
    }
}
